from django.db import models
from django.utils.translation import ugettext as _
from django.contrib.auth.models import User
from fbconnect.__init__ import *

if not settings.AUTH_PROFILE_MODULE:
    raise SiteProfileNotAvailable
try:
    app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
    Profile = models.get_model(app_label, model_name)
except (ImportError, ImproperlyConfigured):
    raise SiteProfileNotAvailable

if not Profile:
    raise SiteProfileNotAvailable


class FBConnectAuth:
	""" Custom authentication for Facebook users"""
	def authenticate(self,fb_uid = None):
		try:
			return Profile.objects.get(fb_uid = fb_uid).user	
		except Profile.DoesNotExist:
			return None			
	
	def get_user(self, user_id):
		try:
			return User.objects.get(pk=user_id)
		except User.DoesNotExist:
			return None
